<template>
  <div>
    <div class="follow" v-if="rfsList">
      <div class="follow-top"></div>
      <!-- 标题 -->
      <div class="follow-title">
        <div class="title-header">
          <h2>新东方美食,会做饭很酷~</h2>
        </div>
        <div class="title-content">
          <h3>你关注人的动态会出现在这</h3>
          <h3>为你推荐了一些有趣的人,快关注 TA 们吧</h3>
        </div>
      </div>
      <!-- 内容 -->
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="getHomeFfeedsFun()"
        style="padding-bottom: 60px"
      >
        <!-- 内容 -->
        <div
          class="follow-content"
          v-for="(item, index) in rfsList"
          :key="index"
          :title="item"
        >
          <div class="content-header">
            <div class="header-img">
              <img :src="item.u.p" alt="" />
            </div>
            <div class="header-user">
              <div class="username">
                <h3>{{ item.u.n }}</h3>
                <span>LV.{{ item.u.lv }}</span>
              </div>
              <div class="user-information">
                <span
                  >{{ item.u.followers_count_text }} ·
                  {{ item.u.recipes_count_text }}</span
                >
              </div>
            </div>
            <div class="header-follow" v-if="isFollow == false">
              <span>关注</span>
            </div>
            <div class="header-follows" v-if="isFollow == true">
              <span>已关注</span>
            </div>
          </div>
          <div class="content-img" @click="jump(item.item_id)">
            <img :src="item.img" alt="" />
          </div>
          <div class="content-footer">
            <div class="footer-top">
              <ul class="top-left" v-if="item.collect_users">
                <li
                  class="imgone"
                  v-for="(k, i) in item.collect_users"
                  :key="i"
                >
                  <img :src="k.p" alt="" />
                  <!-- item.collect_users.p -->
                </li>
                <!-- <li class="imgtwo">
                  <img
                    src="http://tx1.douguo.net/upload/photo/8/0/6/70_u4988624853610329203208.jpg"
                    alt=""
                  />
                </li>
                <li class="imgthree">
                  <img
                    src="http://tx1.douguo.net/upload/photo/3/0/3/70_u4988524853570329203208.jpg"
                    alt=""
                  />
                </li>
                <li class="imgfour">
                  <img
                    src="http://tx1.douguo.net/upload/photo/a/5/4/70_u4988924853980329203210.jpg"
                    alt=""
                  />
                </li> -->
              </ul>
              <div class="top-center">
                <span>{{ item.collect_count_text }}</span>
              </div>
              <div class="top-right">
                <i class="iconfont icon-shoucang"></i>
                <i class="iconfont icon-pinglun"></i>
                <i class="iconfont icon-fenxiang" @click="showShare = true"></i>
              </div>
            </div>
            <div class="footer-center">
              <span>{{ item.t }}</span>
            </div>
          </div>
        </div>
      </van-list>
    </div>

    <van-share-sheet
      v-model="showShare"
      title="立即分享给好友"
      :options="options"
    />
  </div>
</template>

<script>
import { getHomeFfeeds } from "../../api/home/follow";
export default {
  name: "follow",
  data() {
    return {
      loading: false,
      finished: false,
      showShare: false,
      options: [
        [
          { name: "微信", icon: "wechat" },
          { name: "朋友圈", icon: "wechat-moments" },
          { name: "微博", icon: "weibo" },
          { name: "QQ", icon: "qq" },
        ],
        [
          { name: "复制链接", icon: "link" },
          { name: "分享海报", icon: "poster" },
          { name: "二维码", icon: "qrcode" },
          { name: "小程序码", icon: "weapp-qrcode" },
        ],
      ],
      rfsList: [],
      numA: 0,
      numB: 10,
      isFollow: false,
      index: "",
      id: "",
    };
  },
  methods: {
    //获取关注列表
    getHomeFfeedsFun() {
      // 异步更新数据
      getHomeFfeeds({ offset: 0, limit: 20 }).then((data) => {
        // console.log("关注列表数据", data.result.rfs);
        let ids = data.result.rfs.slice(this.numA, this.numB);
        let rfs = ids;

        rfs.filter((value) => {
          this.rfsList.push(value);
        });


        // let rfs = data.result.rfs;
        // console.log(data.result);
        // this.rfsList = rfs;

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (ids.length > 0) {
          this.numA += 10;
          this.numB += 10;
        } else if (ids.length <= 0) {
          this.finished = true;
        }
      });
    },
    //跳转到菜谱详情页面
    jump(id) {
      this.id = id;
      this.$router.push({
        name: "details",
        params: {
          id: this.id,
        },

      });
    },
  },
  created() {
    // this.getHomeFfeedsFun();
  },
};
</script>

<style lang="less">
.follow {
  .follow-top {
    width: 100%;
    height: 105px;
  }
  .follow-title {
    width: 100%;
    height: 90px;
    border-bottom: 2px solid #f2f2f2;
    background-color: #f6f6f6;
    // position: fixed;
    .title-header {
      margin: 0px 15px;
      h2 {
        padding-top: 15px;
        font-size: 14px;
        font-weight: bold;
      }
    }
    .title-content {
      h3 {
        font-size: 12px;
        margin: 5px 15px;
        color: #7f7f7f;
      }
    }
  }
  .follow-content {
    padding-bottom: 10px;
    .content-header {
      margin: 15px 10px;
      display: flex;
      align-items: center;
      .header-img {
        width: 35px;
        height: 35px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .header-user {
        width: 230px;
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        .username {
          font-weight: bold;
          display: flex;
          align-items: center;
          h3 {
            font-size: 14px;
            font-weight: bold;
            color: #000;
          }
          span {
            font-size: 10px;
            color: #c48f23;
            margin-left: 10px;
          }
        }
        .user-information {
          span {
            font-size: 12px;
            color: #868686;
          }
        }
      }
      .header-follow {
        margin-right: 5px;
        span {
          width: 70px;
          height: 30px;
          font-size: 12px;
          font-weight: bold;
          color: #000;
          background-color: #fec538;
          border: 1px solid #fec538;
          border-radius: 50px;
          padding: 5px 20px;
        }
      }
      .header-follows {
        margin-right: 5px;
        span {
          width: 70px;
          height: 30px;
          font-size: 12px;
          font-weight: bold;
          color: #000;
          background-color: #d2d2d2;
          border: 1px solid #d2d2d2;
          border-radius: 50px;
          padding: 5px 18px;
        }
      }
    }
    .content-img {
      width: 100%;
      background-color: #e0e0e0;
      margin-bottom: 12px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .content-footer {
      margin: 0px 12px;
      .footer-top {
        margin: 5px 0px;
        display: flex;
        .top-left {
          width: 20%;
          height: 25px;
          position: relative;
          li:nth-child(1) {
            position: absolute;
            top: 0;
            left: 0;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(2) {
            position: absolute;
            top: 0;
            left: 16px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(3) {
            position: absolute;
            top: 0;
            left: 32px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          li:nth-child(4) {
            position: absolute;
            top: 0;
            left: 48px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background-color: #e6e6e6;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
        }
        .top-center {
          width: 38.6%;
          height: 25px;
          line-height: 25px;
          margin-left: 10px;
          span {
            font-size: 14px;
            // font-weight: bold;
            color: #000;
          }
        }
        .top-right {
          width: 32%;
          height: 25px;
          line-height: 25px;
          margin-left: 15px;
          display: flex;
          justify-content: space-between;
          i {
            font-size: 25px;
          }
        }
      }
      .footer-center {
        width: 93%;
        height: 35px;
        line-height: 35px;
        span {
          display: flex;
          font-size: 16px;
          font-weight: bold;
          color: #000;
        }
      }
    }
  }
}
</style>